layui.use('table', function() {
	var table = layui.table;
	var patrn1 = /^[a-zA-Z0-9]{1}([a-zA-Z0-9]|[._,+-@#$%^&*()~`]){2,20}$/;
	var patrn2 = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	var reg = /^\d{4}$/;

	//忘记密码
	$(".loginbtn").click(function() {
		var phone = $(".phone").val();
		var code = $(".code_num").val();

		if(!patrn2.test(phone)) {
			layer.msg("请输入正确的手机号");
			$(".phone_number").css({ "border": "1px solid red" })
			return false;
		} else {
			$(".phone_number").css({ "border": "1px solid #74767c" })
		}
		if(!reg.test(code)) {
			layer.msg("请输入正确的短信验证码");
			$(".code_left").css({ "border": "1px solid red" })
			$(".code_right").css({ "border": "1px solid red" })
			return false;
		} else {
			$(".code_left").css({ "border": "1px solid #74767c" })
			$(".code_right").css({ "border": "1px solid #74767c" })
		}
		var token = $('#token').val();
		var data = {
			'phone': phone,
			'code': code,
			'_token': token
		};

		var callbackurl = $('#callbackurl').val();
		var index = layer.load(2, {
			shade: [0.2, '#1d89fb'] //0.1透明度的白色背景
				,
			time: 500,
			end: function(e) {
				//				$.ajax({
				//					url: '/dologin',
				//					type: "POST",
				//					data: data,
				//					beforeSend: function() {
				//						$(".loginbtn").attr("disabled", true);
				//					},
				//					success: function(ret) {
				//						
				//					}
				//				});
				$(".login_main").hide();
				$(".login_main2").show();
			}
		});

	});
	//修改密码确认
	$(".new").blur(function() {
		var new_pass = $(".new").val();
		if(!patrn1.test(new_pass)) {
			layer.msg("请输入以数字.大小写字母和标点符号不允许有空格长度3-20位字符密码");
			return false;
		};
	})
	$(".agin").blur(function() {
		var new_pass = $(".new").val();
		var agin_pass = $(".agin").val();
		if(new_pass !== agin_pass) {
			layer.msg("密码不一致请重新输入");
			return false;
		}
	})
	$(".pass_change").click(function() {
		var token = $('#token').val();
		var new_pass = $(".new").val();
		var agin_pass = $(".agin").val();
		var phone = $(".phone").val();
		new_pass = new_pass.toString();
		agin_pass = agin_pass.toString();
		phone = phone.toString();
		based = new Base64();
		new_pass = based.encode(new_pass);
		agin_pass = based.encode(agin_pass);
		phone = based.encode(phone);
		layer.msg("密码修改成功,3秒后自动跳转到登陆...",{
                                    time: 3000,
                                    icon:6,
                                    end:function(e){
                                        window.location.href="login.html";
                                    }
                                });
//		$.ajax({
//			type: "post",
//			data: { "new_pass": new_pass, "_token": token, "agin_pass": agin_pass, "phone": phone },
//			url: "/forget/modifypwd",
//			async: true,
//			beforeSend: function() {
//				$(".pass_change").css("pointer-events", "none");
//			},
//			success: function(data) {
//				if(data.error_code == 0) {
//					
//
//				} else {
//					alert(data.error_message);
//					$(".pass_change").css("pointer-events", "visible");
//
//				}
//			},
//
//		});

	})

	//计时器
	var wait = 60;
	var isclick = true;

	function time(o) {
		wait--;
		o.html(wait);
		if(wait == 0) {
			isclick = true;
			o.html('重新发送');
			wait = 60;
			return false;
		}
		isclick = false;
		setTimeout(function() {
				time(o);
			},
			1000)
	}
	$('#getCode').click(function() {
		var token = $('#token').val();
		if(isclick) {
			var phone = $(".phone").val();
			var patrn2 = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			if(!patrn2.test(phone)) {
				layer.msg("请输入正确的手机号");
				return false;
			}
			var data = {
				'phone': phone,
				'_token': token
			};

			$.ajax({
				url: '/get_code',
				type: "post",
				data: data,
				success: function(ret) {}
			});
			if(phone !== '') {
				time($(this));
			}

		}
	})
})